package com.lanswon.qzsmk.controller.inventoryManageController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.annotation.SystemControllerLog;
import com.lanswon.qzsmk.base.DwzPage;
import com.lanswon.qzsmk.exception.ApplicationException;
import com.lanswon.qzsmk.exception.InventoryException;
import com.lanswon.qzsmk.model.StorageReg;
import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryQueryOfIncomingAndOutRecords")
public class InventoryQueryOfIncomingAndOutRecordsController {
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryQueryOfIncomingAndOutRecordsController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	@RequiresPermissions("inventoryQueryOfIncomingAndOutRecords:index")
	@RequestMapping(name = "出入库清单查询,inventoryQueryOfIncomingAndOutRecords:index",value = "/queryStorageListAndPrint", method = { RequestMethod.POST, RequestMethod.GET })
	@SystemControllerLog(description = "跳转页面")
	public String queryStorageListAndPrint(HttpServletRequest request) {
		return "StorageList";
	}
	

	@RequiresPermissions("inventoryQueryOfIncomingAndOutRecords:getStorageList")
	@RequestMapping(name = "出入库清单信息加载,inventoryQueryOfIncomingAndOutRecords:getStorageList",value = "/getStorageList", method = RequestMethod.POST)
	@ResponseBody
	@SystemControllerLog(description = "提交信息")
	public Map<String, Object> getStorageList(HttpServletRequest request) throws ParseException  {

		// 接收前画面穿过来数据
		String storageDateFrom = request.getParameter("storageDateFromByStorageList");
		String storageDateTo = request.getParameter("storageDateToByStorageList");
		String storageMode = request.getParameter("storageModeByStorageList");
		String branchNo = request.getParameter("branchNoByStorageList");
		//20190128 鱼洲杰修改以下8行
		String startDate = null;
		String endDate=null;
		if(storageDateFrom!=null && !storageDateFrom.equals("")){
		 startDate = new SimpleDateFormat("yyyyMMdd").format(new SimpleDateFormat("yyyy-MM-dd").parse(storageDateFrom));
		}
		if(storageDateTo!=null && !storageDateTo.equals("")) {
		 endDate = new SimpleDateFormat("yyyyMMdd").format(new SimpleDateFormat("yyyy-MM-dd").parse(storageDateTo));
		}
		
		// 装有画面信息的map
		Map<String, String> map = new HashMap<String, String>();
		map.put("storageDateFrom", startDate);
		map.put("storageDateTo", endDate);
		map.put("storageMode", storageMode);
		map.put("storageBranchNo", branchNo);
		
		Map<String, Object> rMap = new HashMap<>();
		rMap = ims.getStorageList(map);
		return rMap;
	}
}
